import os

# 本地图片文件夹路径
source_dir = r"D:\学习\大三上\web课程\finnal\static\images"  # 替换为本地图片文件夹路径

# 输出 SQL 文件路径
output_sql_file = "insert_images.sql"

# 开始生成 SQL 脚本
with open(output_sql_file, "w", encoding="utf-8") as file:
    file.write("USE flask_app;\n")  # 替换为您的数据库名称
    for filename in os.listdir(source_dir):
        if filename.endswith(('.jpg', '.png', '.jpeg')):
            relative_path = f'static/images/{filename}'
            sql = f"INSERT INTO scenic_spots (name, image_url) VALUES ('景区 {filename.split('.')[0]}', '{relative_path}');\n"
            file.write(sql)

print(f"SQL 脚本已生成：{output_sql_file}")